delete a diversion from the list
list points to the second element in the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(Diversion), | intent(inout), | POINTER | :: | list |
header of the list |
|
type(Diversion), | intent(inout), | POINTER | :: | elem |
element to be removed |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(Diversion), | public, | POINTER | :: | current | |||
type(Diversion), | public, | POINTER | :: | prev |
SUBROUTINE DeleteDiversion & ! (list, elem) IMPLICIT NONE !Arguments with intent(inout): TYPE(Diversion), POINTER, INTENT (INOUT) :: list !! header of the list TYPE(Diversion), POINTER, INTENT (INOUT) :: elem !! element to be removed !local declarations TYPE(Diversion), POINTER :: current TYPE(Diversion), POINTER :: prev !---------------------------end of declarations-------------------------------- IF (ASSOCIATED (list, elem) ) THEN !elem is the header of the list list => elem % next !!list points to the second element in the list DEALLOCATE (elem) ELSE !the element to be removed is in the middle of the list current => list prev => list DO WHILE ( ASSOCIATED (current) ) IF ( ASSOCIATED ( current, elem) ) THEN prev % next => current % next DEALLOCATE ( current ) !is also elem EXIT END IF prev => current current => current % next END DO END IF RETURN END SUBROUTINE DeleteDiversion